using UnityEngine;
using System.Collections;

public class SplashManager : MonoBehaviour 
{
	public float timeToElapse;

	private string sceneToLoad = string.Empty;

	private float elapsedTime = 0.0f;

	public Texture texture;

	private void Awake()
	{
		if (PlayerPrefs.GetInt("FirstTime") == Constants.USER_CREATED)
		{
			sceneToLoad = Constants.SCENE_MAIN;
		}
		else 
		{
			sceneToLoad = Constants.SCENE_LOGIN;
		}
	}

	private void Start()
	{
		elapsedTime = 0.0f;
		Time.timeScale = 1f;
	}

	private void Update()
	{
		if (elapsedTime < timeToElapse)
		{
			elapsedTime += Time.deltaTime;
		}
		else
		{
			if (sceneToLoad != "Quit")
			{
				Application.LoadLevel(sceneToLoad);
			}
			else
			{	
				Application.Quit();	
			}
		}

	}

	private void OnGUI()
	{
		GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height), texture);
	}
}